<?php

/**
 * HistoriaClinica form.
 *
 * @package    form
 * @subpackage HistoriaClinica
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class HistoriaClinicaForm extends BaseHistoriaClinicaForm
{
  protected function initialize()
  {
  	$this->labels = array
  	                (
                      'hospital_id'   => 'Hospital',
                      'paciente_id'   => 'Titular',
                      'codigo'        => 'C&oacute;digo',
                      'observaciones' => 'Observaciones',
                      'estado'        => 'Estado',
  	                );
  }
  public function configure()
  {
  	$this->setWidgets(array(
  	  'id'                => new sfWidgetFormInputHidden(),
  	  'hospital_id'       => new sfWidgetFormDoctrineSelect
                             (
                               array
                               (
                                 'model'     => 'Hospital', 
                                 'add_empty' => '---Seleccionar---', 
                                 'order_by'  => array('nombre_corto', 'asc')
                               )
                             ),
      'paciente_id'      => new sfWidgetFormValue(array('value' => $this->getObject()->getPaciente()->getTitular())),
      'codigo'           => new sfWidgetFormInput(),
      'observaciones'    => new sfWidgetFormTextarea(),                                           
      'estado'           => new sfWidgetFormSelect(array('choices' => $this->getTable()->getEstado())),
  	));
  	$this->types = array
  	(
  	 'id'            => '=',
     'paciente_id'   => '-',
     'hospital_id'   => array('combo', array()),
     'codigo'        => 'code',
     'observaciones' => 'text',
     'estado'        => array('combo', array('choices' => array_keys($this->getObject()->getTable()->getEstado()))),
     'slug'          => '-',
     'created_at'    => '-',
     'updated_at'    => '-'
  	);
  }
  public function updateObject($values = null)
  {
    if (is_null($values))
    {
      $values = $this->values;
    }

    $values = $this->processValues($values);
    $values = $this->fixValues($values);
    //Deb::print_r($values);
    $this->object->fromArray($values);
    // embedded forms
    //$this->checkEmbeddedForms($values);
    $this->updateObjectEmbeddedForms($values);
    return $this->object;
  }
  protected function doSave($con = null)
  {
    if (is_null($con))
    {
      $con = $this->getConnection();
    }
    $this->updateObject();

    // i18n table
    if ($this->isI18n())
    {
      $this->updateI18nObjects($con);
    }

    $this->object->save($con);
  }
}